package com.webcash.CNBoard.Service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.webcash.CNBoard.Model.ProjectFile;
import com.webcash.CNBoard.Repository.HistoryRepository;
import com.webcash.CNBoard.Repository.ProjectFileRepository;

@Service
public class ProjectFileServiceImpl implements ProjectFileService {
	@Autowired
	ProjectFileRepository projectFileRepository;
	@Autowired
	HistoryRepository historyRepository;
	
	public void addProjectFilebyProjectFile(ProjectFile file){
		projectFileRepository.insertProjectFilebyProjectFile(file);
		int fileNo = 3;
		historyRepository.addHistoryByProjectNoAndWhereNoAndJobNo(file.getProjectNo(), fileNo, projectFileRepository.selectLastProjectFile());
	}
	
	public List<ProjectFile> getProjectFileList(int projectNo){
		return projectFileRepository.getProjectFileList(projectNo);
		
	}

	public void removeProjectFilebyFileNo(ProjectFile file) {
		projectFileRepository.deleteProjectFilebyFileNo(file);
		int fileWhereNo = 3;
		historyRepository.deleteHistoryByWhereNoAndJobNo(fileWhereNo, file.getFileNo());
		
	}

	public List<ProjectFile> getProjectFileListByProjectNo(int projectNo) {
		return projectFileRepository.getProjectFileList(projectNo);
	}

	public ProjectFile getProjectFileByFileNo(int fileNo) {
		return projectFileRepository.selectProjectFileByFileNo(fileNo);
	}
	
}
